#include "json_helper.hpp"
#include <cassert>
#include <iostream>
#ifdef _WIN32
    #include <windows.h>
#endif // _WIN32

enum class EnumA : std::uint8_t
{
    enum_1 = 10,
    enum_2 = 100
};

struct TestA
{
    double d {1.2};
    bool b {true};
    EnumA enuma {EnumA::enum_1};
    int y {123};
    char str1[2][3][20] {"字符串string1", "字符串string2"};
    char str2[2][3][20] {"字符串string3", "字符串string4", "字符串string5"};
    std::string str3 {"字符串std::string"};
    int array[10] {1, 3, 5, 7, 9};
};

struct TestB
{
    TestA a;
};

struct TestC
{
    TestB b;
    TestA a;
};

REGISTER_STRUCT(TestA, (d)d, (y)y, (str1)str1, (str2)str2, (str3)str3, (array)array, (b)b,
                (enuma)enuma);
REGISTER_STRUCT(TestB, (a)a);
REGISTER_STRUCT(TestC, (b)b, (a)a);

int main()
{
#ifdef _WIN32
    SetConsoleCP(65001);
    SetConsoleOutputCP(65001);
#endif // _WIN32

    rapidjson::StringBuffer s1;
    rapidjson::Writer<rapidjson::StringBuffer> writer1(s1);
    TestC c {};
    JsonHelper::SerializeStruct(writer1, c);
    std::cout << "SerializeStruct TestC: " << s1.GetString() << '\n';

    TestC d;
    memset(&d, 0, sizeof(d));
    rapidjson::Document document1;
    if (document1.Parse(s1.GetString()).HasParseError())
    {
        std::cout << "json HasParseError" << '\n';
    }
    else
    {
        int32_t error_code = 0;
        std::string error_info;
        JsonHelper::DeserializeStruct(document1, d, error_code, error_info);
        if (0 != error_code)
        {
            std::cout << error_code << ":" << error_info << '\n';
        }
    }
    return 0;
}